package com.lbt.eduorder.service.impl;

import com.lbt.commonuntils.ordervo.CourseWebVoOrder;
import com.lbt.commonuntils.ordervo.UcenterMemberOrder;
import com.lbt.eduorder.client.EduClient;
import com.lbt.eduorder.client.UcenterClient;
import com.lbt.eduorder.entity.Order;
import com.lbt.eduorder.mapper.OrderMapper;
import com.lbt.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lbt.eduorder.untils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-06-09
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    EduClient eduClient;
    @Autowired
    UcenterClient ucenterClient;


    @Override
    public String createOrder(String courseId, String userId) {
        //远程调用
        //用户信息
        UcenterMemberOrder ucenterMember = ucenterClient.getUserInfoOrder(userId);
//        System.out.println("///////////////////////////////////"+"\n"+ucenterMember.toString());
        //课程信息
        CourseWebVoOrder courseDto = eduClient.getCourdeInfoOrder(courseId);
//        System.out.println("///////////////////////////////////"+"\n"+courseDto.toString());

        //创建order  对象 向order设置数据  保存数据库
        Order order=new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseDto.getTitle());
        order.setCourseCover(courseDto.getCover());
        order.setTeacherName(courseDto.getTeacherName());
        order.setTotalFee(courseDto.getPrice());
        order.setMemberId(userId);
        order.setMobile(ucenterMember.getMobile());
        order.setNickname(ucenterMember.getNickname());
        order.setStatus(0);     // 支付状态
        order.setPayType(1);    //支付类型
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
